home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cgazv5n5.arc
/
LIST2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-23
|
1KB
|
42 lines
/*--------------------------------------- Listing 2 -------
* Demonstration of the signal() function.
* See Listing 1 for copyright terms.
*-------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
void ExcHandler ( int Signal, int SubCode );
void main ( void );
void ExcHandler ( int Signal, int SubCode )
{
/* Ignore further user interrupts */
if ( signal ( SIGINT, SIG_IGN ) == SIG_ERR )
abort();
printf ( "Signal %d, SubCode %d was raised\n",
Signal, SubCode );
/* Restore to our own exception handler */
if ( signal ( SIGINT, ExcHandler ) == SIG_ERR )
abort();
}
void main ( void )
{
void (*OldHandler)( int Signal );
OldHandler = signal ( SIGINT, ExcHandler );
if ( OldHandler == SIG_ERR )
printf( "signal install failed\n" );
/* Explicitly raise the user-interrupt signal */
raise ( SIGINT );
/* Now that we're done, go back to default signal handler */
if ( signal ( SIGINT, SIG_DFL ) == SIG_ERR )
abort();
}